package recharge_channel_management

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RechargeChannelCreateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 充值渠道--新增
func NewRechargeChannelCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RechargeChannelCreateLogic {
	return &RechargeChannelCreateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RechargeChannelCreateLogic) RechargeChannelCreate(req *types.RechargeChannelCreateRequest) (resp *types.RechargeChannelCreateResponse, err error) {
	rpcReq := rpc.RechargeChannelCreateRequest{
		Type:         req.Type,
		MappingCode:  req.MappingCode,
		Name:         req.Name,
		Level:        req.Level,
		UserGroup:    req.User_group,
		BonusRate:    req.BonusRate,
		MinAmount:    req.MinAmount,
		MaxAmount:    req.MaxAmount,
		AmountConfig: req.AmountConfig,
		MerchantId:   req.MerchantId,
		AppId:        req.AppId,
		SecretKey:    req.SecretKey,
		Url:          req.Url,
		ReturnUrl:    req.ReturnUrl,
		NotifyUrl:    req.NotifyUrl,
		PubKey:       req.PubKey,
		PrivateKey:   req.PrivateKey,
		StartTime:    req.StartTime,
		EndTime:      req.EndTime,
		Sort:         req.Sort,
		Status:       req.Status,
		IsTestable:   req.IsTestable,
		WhiteList:    req.WhiteList,
		Remark:       req.Remark,
		Icon:         req.Icon,
		ChannelName:  req.ChannelName,
		Inr:          req.INR,
	}

	rpcResp, err := l.svcCtx.AssetsRpc.PayRecharge.RechargeChannelCreate(l.ctx, &rpcReq)
	if err != nil {
		return nil, err
	}

	return &types.RechargeChannelCreateResponse{
		CommonResp: types.CommonResp{
			Code:    rpcResp.CommonResp.Code,
			Message: rpcResp.CommonResp.Message,
		},
	}, nil
}
